package com.activemq.spring;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service
public class SpringReceive {
    @Resource
    private JmsTemplate jmsTemplate;

    public static void main(String[] args) {

        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        SpringReceive springReceive = ctx.getBean("springReceive", SpringReceive.class);
        String message;
        while ((message = (String) springReceive.jmsTemplate.receiveAndConvert()) != null) {
            log.info(message);
        }
    }
}
